import apiClient from '@/api/axios.js';

export class FavoriteRecordApi {

  // 查询所有收藏记录
  static async getAllFavoriteRecords() {
    try {
      const response = await apiClient.get('/favoriterecord');
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 根据 favoriteID 查询收藏记录
  static async getFavoriteRecordById(favoriteID) {
    try {
      const response = await apiClient.get(`/favoriterecord/${favoriteID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 根据 userID 查询收藏记录
  static async getFavoriteRecordsByUserId(userID) {
    try {
      const response = await apiClient.get(`/favoriterecord/user/${userID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 新增收藏记录
  static async createFavoriteRecord(params) {
    const { userID, contentID, contentType, creationTime } = params;
    try {
      const response = await apiClient.post('/favoriterecord', {
        userID,
        contentID,
        contentType,
        creationTime
      });
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 更新收藏记录
  static async updateFavoriteRecord(favoriteID, params) {
    const { userID, contentID, contentType, creationTime } = params;
    try {
      const response = await apiClient.put(`/favoriterecord/${favoriteID}`, {
        favoriteID,
        userID,
        contentID,
        contentType,
        creationTime
      });
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 删除收藏记录
  static async deleteFavoriteRecord(favoriteID) {
    try {
      const response = await apiClient.delete(`/favoriterecord/${favoriteID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }
}
